<template>
	<view class="addcart">
		<view class="inputBox">
			<input class="inputitem" v-model="bank_name" type="text" placeholder="银行名称" :disabled="flag">
			<!-- <input class="inputitem" v-model="bank_khh"  type="text" placeholder="开户行"> -->
			<input class="inputitem" v-model="bank_nickname" type="text" placeholder="持卡人" :disabled="flag">
			<input class="inputitem" v-model="bank_card" type="number" placeholder="卡号" :disabled="flag">
		</view>

		<view class="btns" @click="handleSub">
			完成
		</view>

	</view>
</template>

<script>
	import {
		userinfo
	} from "@/api/api.js"
	export default {
		data() {
			return {
				bank_name: "", //银行名称
				bank_khh: "", //开户行
				bank_nickname: "", //持卡人
				bank_card: "", //卡号
				flag:false,
			}
		},
		onLoad() {
			if (!uni.getStorageSync("token")) {
				uni.reLaunch({
					url: "../login/index"
				})
				return
			}
			this.handleGetuserinfo()
		},
		methods: {
			async handleGetuserinfo() {
				let res = await userinfo()
				this.pageData = res.data
				console.log("用户信息", res)
				this.bank_name = res.data.bank_name
				this.bank_khh = res.data.bank_khh
				this.bank_nickname = res.data.bank_nickname
				this.bank_card = res.data.bank_card
				if(res.data.bank_name == null || res.data.bank_khh ==''){
					this.flag = false
				}else{
					this.flag = true
				}
			},
			handleSub() {
				console.log("555", this.bank_name, this.bank_khh, this.bank_nickname, this.bank_card)
				if (this.bank_name == "") {
					uni.showToast({
						title: "请填写银行名称",
						icon: "none",
						duration: 1500
					});
					return
				}
				// if(this.bank_khh == ""){
				// 	uni.showToast({
				// 		title: "请填写开户行",
				// 		icon: "none",
				// 		duration: 1500
				// 	});
				// 	return
				// }
				if (this.bank_nickname == "") {
					uni.showToast({
						title: "请填写持卡人",
						icon: "none",
						duration: 1500
					});
					return
				}
				if (this.bank_card == "") {
					uni.showToast({
						title: "请填写卡号",
						icon: "none",
						duration: 1500
					});
					return
				}
				let yinhangData = {
					bank_name: this.bank_name,
					bank_khh: this.bank_khh,
					bank_nickname: this.bank_nickname,
					bank_card: this.bank_card,
				}
				uni.setStorageSync("yinhangData", yinhangData)
				uni.navigateBack({
					delta: 1
				})
			}

		}
	}
</script>

<style scoped lang="scss">
	page {
		width: 100%;
		min-height: 100%;
		background-color: #ffffff;
	}

	.inputBox {
		margin-top: 57rpx;

		.inputitem {
			width: 630rpx;
			height: 88rpx;
			background: #F2F2F2;
			border-radius: 6rpx 6rpx 6rpx 6rpx;
			margin: 0 auto;
			font-size: 28rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 400;
			line-height: 88rpx;
			text-indent: 16rpx;
			margin-bottom: 46rpx;
		}
	}

	.btns {
		width: 542rpx;
		height: 80rpx;
		background: #04767C;
		border-radius: 512rpx 512rpx 512rpx 512rpx;
		font-size: 36rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		line-height: 80rpx;
		text-align: center;
		margin: 0 auto;
		margin-top: 130rpx;
	}
</style>